﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using DAO;
using BUS;

namespace QuanLyKhachSan
{
    public partial class TraCuuKhachHang : Form
    {
        public TraCuuKhachHang()
        {
            InitializeComponent();
        }

        private void TraCuuKhachHang_Load(object sender, EventArgs e)
        {
            List<LoaiKhachDTO> dsLoaiKhach = LoaiKhachBUS.layDSLoaiKhach();
            for (int i = 0; i < dsLoaiKhach.Count; i++)
            {
                comboLoaiKhach.Items.Add(dsLoaiKhach[i].TenLoaiKhach);
            }
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Chắc chắn muốn thoát ???", "Warning !!!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                this.Close();
        }

        private void btTraCuu_Click(object sender, EventArgs e)
        {
            lvDSKhachHang.Items.Clear();
            List<KhachHangDTO> dsKhachHang = KhachHangBUS.layDSKhachHang();
            for (int i = 0; i < dsKhachHang.Count; i++)
            {
                if (checkBoxTenKH.Checked == true)
                {
                    if (dsKhachHang[i].TenKhachHang.ToLower().Contains(txtTenKH.Text.ToLower()) == false)
                    {
                        dsKhachHang.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
                if (checkBoxLoaiKhach.Checked == true)
                {
                    if (comboLoaiKhach.Text != dsKhachHang[i].LoaiKhach.TenLoaiKhach)
                    {
                        dsKhachHang.RemoveAt(i);
                        i--;
                        continue;
                    }
                }
            }
            for (int i = 0; i < dsKhachHang.Count; i++)
            {
                ListViewItem item = new ListViewItem(new string[] { (i + 1).ToString(), dsKhachHang[i].TenKhachHang, dsKhachHang[i].SoCMND, dsKhachHang[i].LoaiKhach.TenLoaiKhach, dsKhachHang[i].DiaChi });
                lvDSKhachHang.Items.Add(item);
            }
        }
    }
}
